<?php 
	require_once 'util/public.php';
	session_start();
	$islogin = FALSE;
	if(isset($_SESSION['login_user'])){
		$islogin = TRUE;
}?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>公司介绍</title>
<link rel="stylesheet" href="./style/default.css" type="text/css" />
<link rel="stylesheet" href="./style/post.css" type="text/css" />
</head>

<body>
<?php 
// 数据库操作
	require_once 'util/dbconnection.php';
	
  	$request_id = $_GET['id'];
	
  	connect_db();
  	// 请求文章列表
  	$artArray = get_titles_by_category("knowledge");
  	// 直接请求，没有request_id，设置第一篇文章为默认值
  	if( !isset($request_id) ){
  		$ark = array_keys($artArray);
  		$request_id = $ark[0];
  	}
  	$par_post = get_post_by_id( $request_id );
  	
	close_db();
?>

	<div id="page_header">
	</div>
	<div id="nav_line">
	  <ul id="nav_list">
        <li><a href="index.php">网站首页</a></li>
        <li><a href="intro.php">公司介绍</a></li>
        <li><a href="pic_show.php">图片展示</a></li>
        <li class="active"><a href="knowledge.php">花卉知识</a></li>
        <li><a href="contact.php">业务联系</a></li>
        <li><a href="feedback.php">客户留言</a></li>
	  </ul>
	</div>
	
	<div class="body_content"> 
  		<div class="intro_content">
  			<div class="left">
  				<h1>知识列表</h1>
  				<?php 
  					echo "（共".count($artArray)."篇知识）";
  					echo "<ul>";
					foreach( $artArray as $key => $value ){
					  	echo '<li class="art_list"><a href="knowledge.php?id='.$key.'">'.$value['title'].'</a></li>';
					}
					echo "</ul>";
  				?>
  			</div>
  			<div class="right">
  				<?php 
  				if( count($artArray) != 0 ){
  					$tmp = $artArray[$request_id];
			  		echo "<h1>".$tmp['title']."</h1>";
			  		echo '<p class="p_little">本知识由'.$par_post['nick_name'].'添加于'.$par_post['post_date'];
		  			if( $islogin ){
			  			echo '&nbsp;<a href="admin/post-add-edit.php?action=edit&id='.$par_post['id'].'">编辑</a>';
			  		}
			  		echo "</p>";
			  		echo '<div class="post_content">';
			  		echo $par_post['content'];
			  		echo "</div>";
			  		echo '<p class="p_little">知识访问次数:'.$par_post['visit_times']."次</p>";
  				}else{
  					echo "<h1>知识库为空</h1>";
  				}
			  	?>
  			</div>
  		</div>
  	</div>

	 <?php echo_footer($islogin)
  ?>
</body>
</html>
